<?php
require_once("MyNumber.php");
require_once("connect.php");
?>

<html>
<head>
<script type="text/javascript">
function shorten(){
	var urlText = $("input[name=urlText]");
	var url = trim(urlText.val());
	if(url == ""){
		alert("Please provide an URL");
		return;
	}else if(url.indexOf("'") != -1){
		alert("URL cannot contain single quote");
		return;
	}
	var wi = $("div[id=waitInfo]");
	enableBtn("",false);
	wi.text("Shortening your url..");
	$.post("doShorten.php",{url:url}, function(result){
		result = trim(result);
		$("div[id=result]").show();
		var urlSh = $("input[name=urlShort]");
		urlSh.val(result);
		urlSh.select();
		enableBtn("",true);
		wi.text("");
		urlText.val("");
		refresh();
	});
}
</script>
</head>
<body>
<div id="shorten" class="form-group">
	URL : <br>
	<input type="text" name="urlText" class="form-control">
	<button name="shortBtn" type="button" onclick="shorten()">Shorten!</button>
	<br>
	<div id="waitInfo"></div>
	<div id="result" style="display:none">
	<br>Short URL :<br>
	<input type="text" name="urlShort" class="form-control" readonly>
	</div>
</div>
</body>
</html>